<?php

class Empeval_Methods_Request_Login {
	
	/**
	 *
	 * @var App_Methods_Data_App
	 */
	public $app;
	public $email;
	public $password;
	
	public function __construct($params) {
		$this->app = new App_Methods_Data_App($params->app);
		$this->email = $params->email;
		$this->password = $params->password;
	}
	
	public function process() {
		$authResult = Empeval_Auth::getInstance()
		->setLoginData(new Empeval_AuthData_Email($this->email, $this->password))
		->authenticate();
    if ($authResult->isValid())
    	return new Empeval_Methods_Response_Login(true);
    
    $authResult = Empeval_Auth::getInstance()
    ->setLoginData(new Empeval_AuthData_AD($this->email, $this->password))
    ->authenticate();
    if ($authResult->isValid())
    	return new Empeval_Methods_Response_Login(true);
    
    throw new Empeval_Exception_App(Empeval_Exception_Codes::INFO_INCORRECT_LOGIN_PARAMS);
	}
	
}